package swd.basic.enviroment_argument;

import com.pub.database.QueryBean;
import java.util.*;

public class Business {
   QueryBean gqbnDAO=null;
   public Business(QueryBean pqbnDAO){
      gqbnDAO=pqbnDAO;
   }
   String selectTableDataToFld(View view) throws Exception {
      String lstrSQL=null;
      Hashtable<String,Object> lhtTableData=null;
      try{
         lstrSQL="select a.sys_no,a.comm_yn,a.db_kind,a.rs_kind,a.user_no,a.mutli_yn,a.trace_yn," +
                 "       a.page_size,a.use_rs_yn,a.engine_url,a.fld_set_no,a.upload_url," +
                 "       a.backup_path,a.charset_src,a.charset_tag,a.engine_kind,a.lookup_name," +
                 "       a.portal_path,a.report_path,a.rs_run_path,a.show_rs_err,a.show_xml_yn," +
                 "       a.upload_path,a.apserver_url,a.asp_prg_path,a.asp_run_path,a.flow_info_yn," +
                 "       a.homepage_url,a.jsp_prg_path,a.jsp_run_path,a.tomcat_debug," +
                 "       a.apserver_port,a.comm_prg_path,a.asp_frame_path,a.authority_kind," +
                 "       a.db_connect_set,a.jsp_frame_path,a.link_portal_yn,a.comm_graph_path," +
                 "       a.runtime_version,a.authority_set_no,b.employee_name_c,c.sys_name" +
                 "  from wkf_ini_file a left outer join pnl_employee b on a.user_no=b.employee_no left outer join wkf_sys c on a.sys_no=c.sys_no " +
                 " where user_no='" + view.getuser_no() + "'";
         lhtTableData=gqbnDAO.readSingleRowData(lstrSQL);
         if(lhtTableData==null){
            return "查無資料";
         }
         view.setsys_no(String.valueOf((lhtTableData.get("SYS_NO").toString())));
         view.setcomm_yn(String.valueOf((lhtTableData.get("COMM_YN").toString())));
         view.setdb_kind(String.valueOf((lhtTableData.get("DB_KIND").toString())));
         view.setrs_kind(String.valueOf((lhtTableData.get("RS_KIND").toString())));
         view.setuser_no(String.valueOf((lhtTableData.get("USER_NO").toString())));
         view.setmutli_yn(String.valueOf((lhtTableData.get("MUTLI_YN").toString())));
         view.settrace_yn(String.valueOf((lhtTableData.get("TRACE_YN").toString())));
         view.setpage_size(Double.parseDouble((lhtTableData.get("PAGE_SIZE").toString())));
         view.setuse_rs_yn(String.valueOf((lhtTableData.get("USE_RS_YN").toString())));
         view.setengine_url(String.valueOf((lhtTableData.get("ENGINE_URL").toString())));
         view.setfld_set_no(String.valueOf((lhtTableData.get("FLD_SET_NO").toString())));
         view.setupload_url(String.valueOf((lhtTableData.get("UPLOAD_URL").toString())));
         view.setbackup_path(String.valueOf((lhtTableData.get("BACKUP_PATH").toString())));
         view.setcharset_src(String.valueOf((lhtTableData.get("CHARSET_SRC").toString())));
         view.setcharset_tag(String.valueOf((lhtTableData.get("CHARSET_TAG").toString())));
         view.setengine_kind(String.valueOf((lhtTableData.get("ENGINE_KIND").toString())));
         view.setlookup_name(String.valueOf((lhtTableData.get("LOOKUP_NAME").toString())));
         view.setportal_path(String.valueOf((lhtTableData.get("PORTAL_PATH").toString())));
         view.setreport_path(String.valueOf((lhtTableData.get("REPORT_PATH").toString())));
         view.setrs_run_path(String.valueOf((lhtTableData.get("RS_RUN_PATH").toString())));
         view.setshow_rs_err(String.valueOf((lhtTableData.get("SHOW_RS_ERR").toString())));
         view.setshow_xml_yn(String.valueOf((lhtTableData.get("SHOW_XML_YN").toString())));
         view.setupload_path(String.valueOf((lhtTableData.get("UPLOAD_PATH").toString())));
         view.setapserver_url(String.valueOf((lhtTableData.get("APSERVER_URL").toString())));
         view.setasp_prg_path(String.valueOf((lhtTableData.get("ASP_PRG_PATH").toString())));
         view.setasp_run_path(String.valueOf((lhtTableData.get("ASP_RUN_PATH").toString())));
         view.setflow_info_yn(String.valueOf((lhtTableData.get("FLOW_INFO_YN").toString())));
         view.sethomepage_url(String.valueOf((lhtTableData.get("HOMEPAGE_URL").toString())));
         view.setjsp_prg_path(String.valueOf((lhtTableData.get("JSP_PRG_PATH").toString())));
         view.setjsp_run_path(String.valueOf((lhtTableData.get("JSP_RUN_PATH").toString())));
         view.settomcat_debug(String.valueOf((lhtTableData.get("TOMCAT_DEBUG").toString())));
         view.setapserver_port(String.valueOf((lhtTableData.get("APSERVER_PORT").toString())));
         view.setcomm_prg_path(String.valueOf((lhtTableData.get("COMM_PRG_PATH").toString())));
         view.setasp_frame_path(String.valueOf((lhtTableData.get("ASP_FRAME_PATH").toString())));
         view.setauthority_kind(String.valueOf((lhtTableData.get("AUTHORITY_KIND").toString())));
         view.setdb_connect_set(String.valueOf((lhtTableData.get("DB_CONNECT_SET").toString())));
         view.setjsp_frame_path(String.valueOf((lhtTableData.get("JSP_FRAME_PATH").toString())));
         view.setlink_portal_yn(String.valueOf((lhtTableData.get("LINK_PORTAL_YN").toString())));
         view.setcomm_graph_path(String.valueOf((lhtTableData.get("COMM_GRAPH_PATH").toString())));
         view.setruntime_version(String.valueOf((lhtTableData.get("RUNTIME_VERSION").toString())));
         view.setauthority_set_no(String.valueOf((lhtTableData.get("AUTHORITY_SET_NO").toString())));
         view.setusername(String.valueOf((lhtTableData.get("EMPLOYEE_NAME_C").toString())));
         view.setsysnoname(String.valueOf((lhtTableData.get("SYS_NAME").toString())));

         return "";
      }
      catch(Exception e){
         throw new Exception(e.toString());
      }
      finally{
         //lhtTableData.clear();
         lhtTableData=null;
      }
   }
   String exeUpdSQL(View view) throws Exception{
      String lstrSQL=new String();
      Vector<Object> lvtrParam = new Vector<Object>();
      try{
         lvtrParam.add(view.getsys_no()==null ? null :String.valueOf(view.getsys_no()));
         lvtrParam.add(view.getcomm_yn()==null ? null :String.valueOf(view.getcomm_yn()));
         lvtrParam.add(view.getdb_kind()==null ? null :String.valueOf(view.getdb_kind()));
         lvtrParam.add(view.getrs_kind()==null ? null :String.valueOf(view.getrs_kind()));
         lvtrParam.add(view.getuser_no()==null ? null :String.valueOf(view.getuser_no()));
         lvtrParam.add(view.getmutli_yn()==null ? null :String.valueOf(view.getmutli_yn()));
         lvtrParam.add(view.gettrace_yn()==null ? null :String.valueOf(view.gettrace_yn()));
         lvtrParam.add(Double.valueOf(view.getpage_size()));
         lvtrParam.add(view.getuse_rs_yn()==null ? null :String.valueOf(view.getuse_rs_yn()));
         lvtrParam.add(view.getengine_url()==null ? null :String.valueOf(view.getengine_url()));
         lvtrParam.add(view.getfld_set_no()==null ? null :String.valueOf(view.getfld_set_no()));
         lvtrParam.add(view.getupload_url()==null ? null :String.valueOf(view.getupload_url()));
         lvtrParam.add(view.getbackup_path()==null ? null :String.valueOf(view.getbackup_path()));
         lvtrParam.add(view.getcharset_src()==null ? null :String.valueOf(view.getcharset_src()));
         lvtrParam.add(view.getcharset_tag()==null ? null :String.valueOf(view.getcharset_tag()));
         lvtrParam.add(view.getengine_kind()==null ? null :String.valueOf(view.getengine_kind()));
         lvtrParam.add(view.getlookup_name()==null ? null :String.valueOf(view.getlookup_name()));
         lvtrParam.add(view.getportal_path()==null ? null :String.valueOf(view.getportal_path()));
         lvtrParam.add(view.getreport_path()==null ? null :String.valueOf(view.getreport_path()));
         lvtrParam.add(view.getrs_run_path()==null ? null :String.valueOf(view.getrs_run_path()));
         lvtrParam.add(view.getshow_rs_err()==null ? null :String.valueOf(view.getshow_rs_err()));
         lvtrParam.add(view.getshow_xml_yn()==null ? null :String.valueOf(view.getshow_xml_yn()));
         lvtrParam.add(view.getupload_path()==null ? null :String.valueOf(view.getupload_path()));
         lvtrParam.add(view.getapserver_url()==null ? null :String.valueOf(view.getapserver_url()));
         lvtrParam.add(view.getasp_prg_path()==null ? null :String.valueOf(view.getasp_prg_path()));
         lvtrParam.add(view.getasp_run_path()==null ? null :String.valueOf(view.getasp_run_path()));
         lvtrParam.add(view.getflow_info_yn()==null ? null :String.valueOf(view.getflow_info_yn()));
         lvtrParam.add(view.gethomepage_url()==null ? null :String.valueOf(view.gethomepage_url()));
         lvtrParam.add(view.getjsp_prg_path()==null ? null :String.valueOf(view.getjsp_prg_path()));
         lvtrParam.add(view.getjsp_run_path()==null ? null :String.valueOf(view.getjsp_run_path()));
         lvtrParam.add(view.gettomcat_debug()==null ? null :String.valueOf(view.gettomcat_debug()));
         lvtrParam.add(view.getapserver_port()==null ? null :String.valueOf(view.getapserver_port()));
         lvtrParam.add(view.getcomm_prg_path()==null ? null :String.valueOf(view.getcomm_prg_path()));
         lvtrParam.add(view.getasp_frame_path()==null ? null :String.valueOf(view.getasp_frame_path()));
         lvtrParam.add(view.getauthority_kind()==null ? null :String.valueOf(view.getauthority_kind()));
         lvtrParam.add(view.getdb_connect_set()==null ? null :String.valueOf(view.getdb_connect_set()));
         lvtrParam.add(view.getjsp_frame_path()==null ? null :String.valueOf(view.getjsp_frame_path()));
         lvtrParam.add(view.getlink_portal_yn()==null ? null :String.valueOf(view.getlink_portal_yn()));
         lvtrParam.add(view.getcomm_graph_path()==null ? null :String.valueOf(view.getcomm_graph_path()));
         lvtrParam.add(view.getruntime_version()==null ? null :String.valueOf(view.getruntime_version()));
         lvtrParam.add(view.getauthority_set_no()==null ? null :String.valueOf(view.getauthority_set_no()));
         lstrSQL="update wkf_ini_file set sys_no=?,comm_yn=?,db_kind=?,rs_kind=?,user_no=?,mutli_yn=?,trace_yn=?,page_size=?,use_rs_yn=?,engine_url=?,fld_set_no=?,upload_url=?,backup_path=?,charset_src=?,charset_tag=?,engine_kind=?,lookup_name=?,portal_path=?,report_path=?,rs_run_path=?,show_rs_err=?,show_xml_yn=?,upload_path=?,apserver_url=?,asp_prg_path=?,asp_run_path=?,flow_info_yn=?,homepage_url=?,jsp_prg_path=?,jsp_run_path=?,tomcat_debug=?,apserver_port=?,comm_prg_path=?,asp_frame_path=?,authority_kind=?,db_connect_set=?,jsp_frame_path=?,link_portal_yn=?,comm_graph_path=?,runtime_version=?,authority_set_no=? where user_no='" + view.getuser_no() + "'";
         if(!gqbnDAO.executeSQL(lstrSQL,lvtrParam)){
            return "wkf_ini_file";
         }
         return "存檔成功";
      }
      catch(Exception e){
         e.printStackTrace();
         throw new Exception(e.toString());
      }
      finally{
         lvtrParam.clear();
      }
   }
   String exeInsSQL(View view) throws Exception{
      String lstrSQL=new String();
      Vector<Object> lvtrParam = new Vector<Object>();
      try{
         lvtrParam.add((view.getuser_no()==null ? null : view.getuser_no()));
         lvtrParam.add((view.getruntime_version()==null ? null : view.getruntime_version()));
         lvtrParam.add((view.getdb_kind()==null ? null : view.getdb_kind()));
         lvtrParam.add((view.getdb_connect_set()==null ? null : view.getdb_connect_set()));
         lvtrParam.add((view.getpage_size()==0 ? null : Double.valueOf(view.getpage_size())));
         lvtrParam.add((view.getflow_info_yn()==null ? null : view.getflow_info_yn()));
         lvtrParam.add((view.getlink_portal_yn()==null ? null : view.getlink_portal_yn()));
         lvtrParam.add((view.getportal_path()==null ? null : view.getportal_path()));
         lvtrParam.add((view.gettrace_yn()==null ? null : view.gettrace_yn()));
         lvtrParam.add((view.getasp_prg_path()==null ? null : view.getasp_prg_path()));
         lvtrParam.add((view.getjsp_prg_path()==null ? null : view.getjsp_prg_path()));
         lvtrParam.add((view.getasp_run_path()==null ? null : view.getasp_run_path()));
         lvtrParam.add((view.getjsp_run_path()==null ? null : view.getjsp_run_path()));
         lvtrParam.add((view.getrs_run_path()==null ? null : view.getrs_run_path()));
         lvtrParam.add((view.getasp_frame_path()==null ? null : view.getasp_frame_path()));
         lvtrParam.add((view.getjsp_frame_path()==null ? null : view.getjsp_frame_path()));
         lvtrParam.add((view.getbackup_path()==null ? null : view.getbackup_path()));
         lvtrParam.add((view.getshow_xml_yn()==null ? null : view.getshow_xml_yn()));
         lvtrParam.add((view.getuse_rs_yn()==null ? null : view.getuse_rs_yn()));
         lvtrParam.add((view.getshow_rs_err()==null ? null : view.getshow_rs_err()));
         lvtrParam.add((view.getcharset_src()==null ? null : view.getcharset_src()));
         lvtrParam.add((view.getcharset_tag()==null ? null : view.getcharset_tag()));
         lvtrParam.add((view.getlookup_name()==null ? null : view.getlookup_name()));
         lvtrParam.add((view.gethomepage_url()==null ? null : view.gethomepage_url()));
         lvtrParam.add((view.gettomcat_debug()==null ? null : view.gettomcat_debug()));
         lvtrParam.add((view.getfld_set_no()==null ? null : view.getfld_set_no()));
         lvtrParam.add((view.getauthority_kind()==null ? null : view.getauthority_kind()));
         lvtrParam.add((view.getauthority_set_no()==null ? null : view.getauthority_set_no()));
         lvtrParam.add((view.getrs_kind()==null ? null : view.getrs_kind()));
         lvtrParam.add((view.getupload_path()==null ? null : view.getupload_path()));
         lvtrParam.add((view.getupload_url()==null ? null : view.getupload_url()));
         lvtrParam.add((view.getengine_url()==null ? null : view.getengine_url()));
         lvtrParam.add((view.getengine_kind()==null ? null : view.getengine_kind()));
         lvtrParam.add((view.getapserver_url()==null ? null : view.getapserver_url()));
         lvtrParam.add((view.getapserver_port()==null ? null : view.getapserver_port()));
         lvtrParam.add((view.getsys_no()==null ? null : view.getsys_no()));
         lvtrParam.add((view.getcomm_graph_path()==null ? null : view.getcomm_graph_path()));
         lvtrParam.add((view.getcomm_prg_path()==null ? null : view.getcomm_prg_path()));
         lvtrParam.add((view.getcomm_yn()==null ? null : view.getcomm_yn()));
         lvtrParam.add((view.getreport_path()==null ? null : view.getreport_path()));
         lvtrParam.add((view.getmutli_yn()==null ? null : view.getmutli_yn()));
         lstrSQL="insert into wkf_ini_file(user_no,runtime_version,db_kind,db_connect_set,page_size,flow_info_yn,link_portal_yn,portal_path,trace_yn,asp_prg_path,jsp_prg_path,asp_run_path,jsp_run_path,rs_run_path,asp_frame_path,jsp_frame_path,backup_path,show_xml_yn,use_rs_yn,show_rs_err,charset_src,charset_tag,lookup_name,homepage_url,tomcat_debug,fld_set_no,authority_kind,authority_set_no,rs_kind,upload_path,upload_url,engine_url,engine_kind,apserver_url,apserver_port,sys_no,comm_graph_path,comm_prg_path,comm_yn,report_path,mutli_yn) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
         if(!gqbnDAO.executeSQL(lstrSQL,lvtrParam)){;
            return "wkf_ini_file";
         }
         lvtrParam.clear();

         return "";
      }
      catch(Exception e){
         e.printStackTrace();
         throw new Exception(e);
      }
      finally{
         lvtrParam.clear();
      }
   }
   String checkNotNullFld(View view) throws Exception{
      StringBuffer lstbNullFldList=new StringBuffer();
      return (lstbNullFldList.toString().equals("") ? "" : lstbNullFldList.delete(lstbNullFldList.length()-1,lstbNullFldList.length()).toString());
   }
   void setInitValueForAdd(View view,String pstrUserID) throws Exception{
      view.setruntime_version("JSP");
      view.setdb_kind("ORACLE");
      view.setpage_size(10);
      view.setflow_info_yn("Y");
      view.setlink_portal_yn("Y");
      view.settrace_yn("N");
      view.setshow_xml_yn("N");
      view.setuse_rs_yn("Y");
      view.setshow_rs_err("N");
      view.setrs_kind("X");
      view.setcomm_yn("N");
   }
   void setReadonlyForAdd(View view) throws Exception{
   }

}
